﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using DatabaseLayer;

namespace IVRJunctionUI
{
    public partial class ConfigureOptions : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (ListModerationType.SelectedValue.Equals("1"))
            {
                TableRowSyncBranch.Visible = true;
                TableRowSyncBranchOption.Visible = true;
                TableRowNeedFacebook.Visible = true;
                TableRowFacebookOption.Visible = true;
            }
            else
            {
                TableRowSyncBranch.Visible = false;
                TableRowSyncBranchOption.Visible = false;
                TableRowNeedFacebook.Visible = false;
                TableRowFacebookOption.Visible = false;
            }

        }

        protected void ButtonSubmit_Click(object sender, EventArgs e)
        {
            bool isModerationOnline = false;
            bool isSynchronizeBranch = false;
            bool isConfigureFacebook = false;

            if (ListModerationType.SelectedValue.Equals("1"))
            {
                isModerationOnline = true;
                if (ListSyncBranch.SelectedValue.Equals("0"))
                    isSynchronizeBranch = true;

                if (ListNeedFacebook.SelectedValue.Equals("0"))
                    isConfigureFacebook = true;
            }
            DatabaseFunctions objectDatabaseFunctions = new DatabaseFunctions();

            bool isDBDeleteOperationSuccess = objectDatabaseFunctions.deleteIVRJunctionConfiguration();
               
            
            if (isDBDeleteOperationSuccess)
            {
                bool isDBInsertOperationSuccess = objectDatabaseFunctions.insertOrUpdateGenericConfiguration(isModerationOnline, isSynchronizeBranch, isConfigureFacebook);

                if (isDBInsertOperationSuccess)
                {
                    Response.Redirect("~/Configuration.aspx");
                }
            }

            

        }

    }
}